<template>
  <div>
    <van-tabs v-model:active="formData.active" swipeable @click="onClickTab">
      <van-tab :title="item.name" v-for="(item,index) in tabList" :key="index">
        <van-pull-refresh v-model="formData.refreshing" @refresh="onRefresh">
          <van-list v-model:loading="formData.loading" :finished="formData.finished" finished-text="无更多记录" @load="onload" :immediate-check="false">
            <ul v-if="DataList.length">
              <li v-for="(item,index) in DataList" :key="index" @click="GoOrder(item.id)">
                <van-row class="li">
                  <van-col span="8">
                    <div class="img-box">
                      <img :src="item.collection.cover" class="img" v-if="VideoIndexOf(item.collection.cover)" />
                      <vueVideo :src="item.collection.cover" class="video" v-else />
                    </div>
                  </van-col>
                  <van-col span="11" class="line">
                    <div class="record-cont">
                      <h1>{{item.collection.name}} </h1>
                      <h2>数量：{{item.number?item.number:"1"}}</h2>
                      <h2>接收人：{{item.userMobile}}</h2>
                      <p>{{item.createTime}}</p>
                    </div>
                  </van-col>
                  <van-col span="5" class="space-between">
                    <span :class="{'green': item.state == 1}">{{item.stateDesc}}</span>
                    <p>￥ {{item.collection.price?item.collection.price:"0"}}</p>
                  </van-col>
                </van-row>
              </li>
            </ul>
            <!-- <van-empty description="暂无订单记录" v-else /> -->
          </van-list>
        </van-pull-refresh>
      </van-tab>

    </van-tabs>

  </div>

</template>
<script>
import { ref, defineComponent, reactive, onMounted, toRefs, nextTick, computed } from "vue";
import { conversionList } from "@/api/public";
import { Toast } from "vant";
import { useStore } from "vuex";
import { useRouter } from "vue-router"
import { VideoIndexOf } from "@/utils/phone";
import vueVideo from "@/components/video.vue";
export default {
  components: { vueVideo },
  setup() {
    const DataList = ref([])
    const store = useStore();
    const router = useRouter()
    const user_info = computed(() => {
      return store.getters.user_info
    })
    const menList = reactive([
      {
        id: 0, name: "藏品"
      },
      {
        id: 3, name: "盲盒"
      },
    ])
    const formData = reactive({
      tab: 3,
      page: 1,
      size: 10,
      active: 0,
      total: 0,
      type: null,
      loading: true,
      finished: false,
      isActive: true,
      hasError: false

    })
    const getTab = async (id) => {
      formData.tab = id
      formData.page = 1
      formData.active = 0
      DataList.value = []
      onload()
    }
    const GoOrder = (id) => {
      // router.push({
      //   path: '/details',
      //   // /details
      //   query: {
      //     id: id
      //   }
      // })
    }
    const onRefresh = () => {
      DataList.value = []
      formData.page = 1
      formData.total = 0
      formData.loading = false
      formData.finished = false
      formData.refreshing = true
      Toast('刷新成功');

      onload()

    }
    const onClickTab = (index) => {

      console.log(index)
      // formData.finished = true,
      //   formData.loading = false
      formData.page = 1
      DataList.value = []

      if (index == 0) {
        formData.type = null
      } else {
        formData.type = index
      }
      onload()

    }
    onMounted(() => {
      onload()
    })
    const onload = async () => {

      formData.finished = false
      formData.loading = true
      console.log(formData.finished, formData.loading)
      const data = {
        pageNum: formData.page,
        pageSize: formData.size,
        state: formData.type,
        mode: formData.type,
        collectionPropType: formData.tab
      }
      const res = await conversionList(data)
      formData.loading = false
      formData.total = res.data.data.total
      DataList.value = DataList.value.concat(res.data.data.records)
      formData.page++
      if (formData.finished) {
        formData.loading = true
      }
      if (formData.refreshing) {
        formData.refreshing = false
      }
      console.log(formData.total, DataList.value.length)
      if (res.data.data.records.length == 0) {
        formData.page = 1
        formData.loading = false
        formData.finished = true;
      } else {
        if (formData.total == DataList.value.length) {
          console.log("不加载")
          formData.finished = true;
          formData.loading = false
          return false
        } else {
          formData.finished = false;
          console.log("加载")

        }
      }


    }
    const tabList = reactive([
      {
        id: null,
        name: '全部'
      },
      {
        id: 2,
        name: '我的赠与'
      },
      {
        id: 1,
        name: '收到赠与'
      },
    ])
    return {
      menList,
      onload,
      tabList,
      formData,
      onRefresh,
      DataList,
      onClickTab,
      GoOrder,
      getTab,
      VideoIndexOf
    }
  }

}
</script>

<style lang="less" scoped>
&:deep(.van-tabs__wrap) {
  background: transparent;
}
&:deep(.van-tabs__nav) {
  background: transparent !important;
  margin: 0px 20px;
}
&:deep(.van-tab) {
  font-size: 31px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #ffffff;
  opacity: 0.8;
}
&:deep(.van-tab--active) {
  .van-tab__text {
    font-size: 36px;
    font-family: Source Han Sans CN;
    font-weight: bold;

    background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}
&:deep(.van-tabs__line) {
  background: url('../../../assets/image/tab-active.png');
  background-size: 100% 100%;
  bottom: 40px !important;
}
ul {
  margin: 0px 20px;
  li {
    background: #282a2c;
    border-radius: 20px;
    margin-top: 30px;
    padding: 20px 20px;
    .img-box {
      width: 200px;
      height: 200px;
      background: linear-gradient(0deg, #161718, #4b4c4d);
      border: 2px solid #ffffff;
      border-radius: 20px;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .record-cont {
      h1 {
        height: 30px;
        font-size: 32px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
        line-height: 53px;
        margin: 0px;
      }
      h2 {
        height: 25px;
        font-size: 26px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #b9c4c7;
        line-height: 48px;
        margin-top: 25px;
      }
      p {
        height: 20px;
        font-size: 26px;
        font-family: Source Han Sans CN;
        font-weight: 300;
        color: #b9c4c7;
        line-height: 48px;
      }
    }
    .space-between {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: flex-end;
      span {
        font-size: 32px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
        line-height: 73px;

        background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
      p {
        font-size: 40px;
        font-family: Source Han Sans CN;
        font-weight: bold;
        color: #ffffff;
        line-height: 73px;

        background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
    }
  }
}
.title {
  .tabactive {
    font-size: 36px !important;
    font-weight: bold !important;
    color: #ffffff !important;
  }
  padding-left: 20px;
  height: 80px;
  background: #222;
  display: flex;
  align-items: center;
  &:deep(.icon) {
    color: #ffffff;
    font-size: 50px;
  }
  .tab {
    padding-left: 40px;
    span {
      font-size: 36px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #b9c4c7;
      display: inline-block;
      margin-right: 80px;
    }
  }
}
</style>